package demo1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class TestStudent {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        do {
            System.out.println("请选择您的操作：1.显示全部学员2.删除3.增加4.修改0.退出");
            try {
                int num=input.nextInt();
                switch (num){
                    case 1:
                        List<Student>students=StudentManager.findAll();
                        for (int i = 0; i <students.size() ; i++) {
                            Student student=students.get(i);
                            System.out.println("student.toString() = " + student.toString());
                        }
                        break;
                    case 2:
                        System.out.println("请输入删除的姓名");
                        String names=input.next();
                        boolean results=StudentManager.deleteSong(names);
                        if (results){
                            System.out.println("删除成功");
                        }
                        else {
                            System.out.println("您输入姓名不存在");
                        }
                        break;
                    case 3:
                        System.out.println("请输入学号");
                        String id=input.next();
                        System.out.println("请输入姓名");
                        String name=input.next();
                        System.out.println("请输入年龄");
                        int age=input.nextInt();
                        Student student=new Student(id,name,age);
                        boolean result =StudentManager.adds(student);
                        if(result) {
                            System.out.println("新增学员成功!");
                        }
                        else {
                            System.out.println("学员名重复，添加失败！");
                        }
                        break;
                    case 4:
                        System.out.println("请输入修改的学员姓名");
                        name=input.next();
                        System.out.println("请输入修改后学号");
                         id=input.next();
                        System.out.println("请输入修改后年龄");
                         age=input.nextInt();
                         student=new Student(id,name,age);
                         result =StudentManager.mod(student);
                        if(result) {
                            System.out.println("修改学员成功!");
                        }
                        else {
                            System.out.println("学员名不存在，修改失败！");
                        }
                        break;
                    case 0:
                        System.out.println("欢迎下次使用");
                           System.exit(0);
                           break;
                    default:
                        System.out.println("没有您要的选项");
                        break;
                }
            }catch (Exception ex){
                System.out.println("没有您要的选项");
                input=new Scanner(System.in);
            }
        }while (true);

    }
}
